# -*- coding:utf-8 -*-
'''
author:leedom
说明:该方法是一次性抓取五帧，对其求平均，之后调用sample文件中的方法进行红色区域的处理
运行：直接在其目录下，运行该文件即可
'''
import cv2 
import numpy as np 
import sample
def redRecognition():
    cap = cv2.VideoCapture(0) 
    count = 1     #计数器
    while(1): # get a frame 
        ret1, frame1 = cap.read() # show a frame 
        ret2, frame2 = cap.read() # show a frame 
        ret3, frame3 = cap.read() # show a frame 
        ret4, frame4 = cap.read() # show a frame 
        ret5, frame5 = cap.read() # show a frame 

        img1 = frame1.astype(np.float32)
        img2 = frame1.astype(np.float32)
        img3 = frame1.astype(np.float32)
        img4 = frame1.astype(np.float32)
        img5 = frame1.astype(np.float32)
        img = (img1+img2+img3+img4+img5)/5
        img = img.astype(np.uint8)

        d = sample.Detect(img)
        length,angle = d.img_process_main(count)   
        count += 1
        if cv2.waitKey(40) & 0xFF == ord('q'): 
            break
        return length,angle
    cap.release() 
    cv2.destroyAllWindows() 
    

if __name__ == '__main__':
    redRecognition()
